package org.example;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

class Item implements Comparable<Item> {
    int value;
    int idx;
    Item(int value, int idx) {
        this.value = value;
        this.idx = idx;
    }

    @Override
    public int compareTo(Item o) {
        return Integer.compare(this.value, o.value);
    }
}

class Solution {
    public int[] smallerNumbersThanCurrent(int[] nums) {
        Item[] items = new Item[nums.length];
        for (int i = 0; i < nums.length; i++) {
            items[i] = new Item(nums[i], i);
        }
        Arrays.sort(items);

        int[] ans = new int[nums.length];
        ans[items[0].idx] = 0;
        int curIdx = 0;
        int curValue = items[0].value;
        for (int i = 1; i < nums.length; i++) {
            if (items[i].value != curValue) {
                curIdx = i;
                curValue = items[i].value;
            }
            ans[items[i].idx] = curIdx;
        }
        return ans;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}